
Vue.createApp({
    // 定义组件
    components:{
        "my-article": ARTICLE
    },
    // 初始化
    setup(){
        // reactive定义变量运行存储
        // toRefs将数据返回
        const {
            reactive, toRefs
        } = Vue
        // 定义变量，即所需数据
        const state = reactive({
            articles: {},
            page: 1,
            limit: 10,
            signInInfo: {}
        })
        let that = state
        $.get("/getRecommendArticle/" + state.page + "/" + state.limit, function(data){
            that.articles = data
        });
        get("/signInInformation", function(data){
            state.signInInfo = data;
        })
        // 返回数据
        return {
            ...toRefs(state)
        }
    },
    methods:{
        // 更多推荐
        more(){
            let that = this
            that.page += 1
            $.get("/getRecommendArticle/" + that.page + "/" + that.limit, function(data){
                console.log(that.page);
                console.log(data);
                if (data.length == 0) {
                    swalError("暂无更多推荐")
                } else {
                    that.articles = that.articles.concat(data)
                }
            });

        },
        sign(){
            let that = this;
            get("/signIn", function(data){
                if (data == 1) {
                    get("/signInInformation", function(data){
                        that.signInInfo = data;
                        swalSuccess("签到成功", "坚持总是酷酷滴，新的一天，加油！")
                    })
                } else {
                    swalError("签到失败", "系统竟然崩溃了，攻城狮正修复中...")
                }
            })
        }
    }
    // 绑定app
}).mount("#recommend")